package com.muyu.product.domain.resp;

import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.RuleInfo;
import com.muyu.product.domain.model.RuleAttrAddModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.function.Function;

/**
 * @author DongZl
 * @description: 规格返回结果集
 * @Date 2024-3-4 下午 04:08
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class RuleInfoResp extends BaseEntity {

    private Long id;

    /** 规格名称 */
    private String name;

    /** 规格状态 */
    private String status;

    /**
     * 规格属性集合
     */
    private List<RuleAttrAddModel> ruleAttrList;

    public static RuleInfoResp infoBuild (RuleInfo ruleInfo, Function<Long, List<RuleAttrAddModel>> ruleAttrList) {
        return RuleInfoResp.builder()
                .id(ruleInfo.getId())
                .name(ruleInfo.getName())
                .status(ruleInfo.getStatus())
                .ruleAttrList(ruleAttrList.apply(ruleInfo.getId()))
                .build();
    }
}
